﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace NutriFast
{
    public partial class RecetaDel : Form
    {
        public RecetaDel()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (grid1.Rows.Count != 0)
            {
                try
                {

                    if (grid1.Rows.Count >= 1)
                    {
                        if (MessageBox.Show(this, "¿Seguro que desea eliminar la receta?", "Confirmación", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                        {
                            int index = grid1.CurrentRow.Index;
                            if (dbPeri.DelReceta(int.Parse("" + grid1.Rows[index].Cells[0].Value)) && dbPeri.DelRecetaFood(int.Parse("" + grid1.Rows[index].Cells[0].Value)))
                            {
                                grid1.Rows.RemoveAt(grid1.CurrentRow.Index);
                            }
                        }
                    }

                }
                catch (System.Exception ex)
                {
                    System.Windows.Forms.MessageBox.Show(ex.Message);
                }
            }//fin del otro if
            else
            {
                errorProvider1.SetError(txtNombre, "Obligatorio");
            }//fin del else
        }

        private void txtNombre_TextChanged(object sender, EventArgs e)
        {
            this.spPeriquinSerchRecetaTableAdapter.Fill(this.dsPeriquinSearchReceta.spPeriquinSerchReceta, txtNombre.Text);
        }

        private void RecetaDel_Load(object sender, EventArgs e)
        {
            txtNombre_TextChanged(null, null);
        }
    }
}
